package com.cheer.vo;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.cheer.dto.MemberImportDTO;
import lombok.Data;
import lombok.experimental.Accessors;

import java.text.NumberFormat;
import java.util.List;

/**
 * @author cheer
 */
@Data
@Accessors(chain = true)
public class DocumentMemberVO extends DocumentVO {

    private Integer personNumber;

    private Integer youthNumber;

    private String youthPercent;

    private String contactPersonPost;

    private String contactPersonBirth;

    private Integer contactPersonAge;

    public static DocumentMemberVO build(String fileName, String fileUrl, String resourceUrl, List<MemberImportDTO> members) {
        // 文件信息
        DocumentMemberVO documentMemberVO = new DocumentMemberVO();
        documentMemberVO.setName(fileName);
        documentMemberVO.setUrl(fileUrl);
        documentMemberVO.setLink(resourceUrl + fileUrl);
        // 成员信息
        documentMemberVO.setPersonNumber(members.size());
        documentMemberVO.setYouthNumber((int) members.stream()
                .filter(memberImportDTO -> memberImportDTO.getAge() < 35)
                .count());
        NumberFormat nt = NumberFormat.getPercentInstance();
        documentMemberVO.setYouthPercent(nt.format(1.0 * documentMemberVO.getYouthNumber() /
                documentMemberVO.getPersonNumber()));
        // 负责人信息
        MemberImportDTO leader = members.get(0);
        documentMemberVO.setContactPersonBirth(DateUtil.format(leader.getBirth(), DatePattern.NORM_DATE_FORMAT));
        documentMemberVO.setContactPersonAge(leader.getAge());
        documentMemberVO.setContactPersonPost(leader.getAddPostDescription());
        return documentMemberVO;
    }

}
